<?php
namespace app\common\netfilter;

class Windows2003Rule
{
    public $rulehead = 'netsh firewall';//规则头部
    private $protocols ; //协议
    private $direction ; //流量方向
    /**
     * @name: 状态
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-13 16:57:14
     */
    function status ($status)
    {
        $return = $status != 1 ? 'delete' : 'set';

        return $return;
    }

    /**
     * @name: 端口开启
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-13 17:05:05
     */
    function portopen ()
    {
        return 'portopening';
    }

    /**
     * @name: 流量方向
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-13 17:24:47
     */
    function direction ($direction)
    {
        $this->direction = $direction;
    }

    /**
     * @name: 协议
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-13 17:05:57
     */
    function protocols ($prototols)
    {
        $return = '';
        if($prototols == 3)
        {
            return $return;
        }

        // $return = 'protocol=';
        $return .= $this->protocols = $prototols == 1  ? 'TCP' : 'UDP';
        
        return $return;
    }

    /**
     * @name: 端口
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-13 17:10:55
     */
    function port ($src_port, $dest_port)
    {
        $return = '';

        $port = $this->direction == 1 ? $src_port : $dest_port;

        if($this->protocols == 3 || $port == 'any')
        {
            return $return;
        }

        // $return = 'port=' . $port;
        $return = $port;

        return $return;
    }

    /**
     * @name: 规则名
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-13 17:17:59
     */
    function alias ($alias)
    {
        return $alias;
    }
}